package xiaojian.toolkit.netty.handler.codec.http.transformer;

import org.apache.commons.collections4.Transformer;

import xiaojian.toolkit.bean.BeanUtils;
import io.netty.handler.codec.http.FullHttpRequest;

public class CheckRequiredTransformer implements HttpRequestTransformer {

	private Transformer impl;

	public Transformer getImpl() {
		return impl;
	}

	public void setImpl(Transformer impl) {
		this.impl = impl;
	}

	@Override
	public Object transform(FullHttpRequest from) {
		Object bean = impl.transform(from);
		if (null != bean) {
			try {
				BeanUtils.checkRequired(bean);
			} catch (Exception exception) {
				throw new HttpTransformException(MISS_REQUIERD_ATTR_CODE,
						MISS_REQUIERD_ATTR_DESC);
			}
		}
		return bean;
	}

}
